package com.web.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.domain.CarModelVo;
import com.business.domain.CarSeriesVo;
import com.business.service.CarService;
import com.sys.Utils.DbConstants;
import com.sys.dao.DictItemMapper;
import com.sys.domain.DictItem;
import com.sys.domain.DictItemExample;
import com.sys.domain.DictItemExample.Criteria;
import com.sys.result.RequestPageVo;
import com.sys.result.RequestResultVo;

@Controller
@RequestMapping("/web")
public class CarInputController {
	
	@Resource
	public CarService carService;
	@Resource
	private DictItemMapper dictItemMapper;

	@RequestMapping("")
	public String toCarInput(Model model){
		
		model.addAttribute("brandList", carService.getCarBrandByModel());
		model.addAttribute("provinceList", carService.getAllProvince());
		DictItemExample example =new DictItemExample();
		example.setOrderByClause("item_order");
		Criteria Criteria=example.createCriteria();
		Criteria.andDictCodeEqualTo(DbConstants.LOAN_PERIOD);
		List<DictItem> dictItemList = dictItemMapper.selectByExample(example);
		model.addAttribute("dictItemList", dictItemList);
		
		return "car/carinput";
	}
	
	@RequestMapping("/car/getSeriesListByBrandId")
	public @ResponseBody RequestPageVo<CarSeriesVo> getSeriesListByBrandId(Integer brandId){
		
		return carService.getSeriesListByBrandIdAndModelId(brandId);
	}
	
	@RequestMapping("/car/getModelListBySeriesId")
	public @ResponseBody RequestPageVo<CarModelVo> getModelListBySeriesId(Integer seriesId){
		
		return carService.getModelListBySeriesId(seriesId);
	}
	
	@RequestMapping("/car/getModelByModelId")
	public @ResponseBody RequestResultVo<CarModelVo> getModelByModelId(Integer modelId,Integer provinceId){
		
		return carService.getModelByModelId(modelId,provinceId);
	}
	
}
